<template>
  <div>
    <div class="login_box">
      <h1>UNI-ADMIN</h1>
      <el-form
        :model="form"
        status-icon
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item prop="user">
          <el-input
            type="text"
            placeholder="请输入用户名"
            v-model="form.user"
          ></el-input>
        </el-form-item>
        <el-form-item prop="pass">
          <el-input
            type="password"
            placeholder="请输入用户名"
            v-model="form.pass"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="button_login" @click="login"
            >立即登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        user: "",
        pass: "",
      },
    };
  },
  methods: {
    login() {
      //通过请求接口获取数据
      this.$axios
        .post("http://ceshi5.dishait.cn/admin/login", {
          username: this.form.user,
          password: this.form.pass,
        })
        .then((res) => {
          localStorage.setItem("token", res.data.data.token);
          this.$router.push({ path: "/home" });
        })
        .catch((res) => {
          console.log(res);
          alert("登陆失败，用户名或密码错误");
        });
    },
  },
};
</script>

<style lang="scss">
* {
  margin: 0;
  padding: 0;
}
h1{
  width: 100%;
  margin: 0 auto;
  text-align: center;
  margin-right: -52px;
}
.login_box {
  width: 600px;
  height: 400px;
  border: 1px solid grey;
  margin: 15% auto;
  box-sizing: border-box;
  padding-right: 60px;
  padding-top: 70px;
  // 登录
  .button_login {
    width: 100%;
    background: rgb(0, 128, 128);
    outline: none;
    border: none;
  }
}
</style>